package com.lagou.order.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lagou.common.pojo.Goods;
import com.lagou.common.pojo.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface OrderMapper extends BaseMapper<Order> {

    /**
     * 根据订单id查询订单
     * @param id
     * @return
     */
    @Select("select * from `order` where id = #{id}")
    public Order getOrderById(@Param("id") String id);

    /**
     * 分页查询
     * @param timeB 开始时间
     * @param timeE 结束时间
     * @param status 支付状态
     * @param offset
     * @param pageSize
     * @return
     */
    @Select("<script> " +
            "SELECT * FROM `order` " +
            "WHERE 1=1 " +
            "AND create_time BETWEEN #{timeB} AND #{timeE} " +
            "AND `status` = #{status} " +
            "LIMIT #{offset}, #{pageSize}" +
            "</script>")
    public List<Order> getAllOrder(@Param("timeB") String timeB,
                                   @Param("timeE") String timeE,
                                   @Param("status") Integer status,
                                   @Param("offset") Integer offset,
                                   @Param("pageSize") Integer pageSize);

    /**
     * 查询order信息数
     * @param timeB
     * @param timeE
     * @param status
     * @return
     */
    @Select("<script> " +
            "SELECT COUNT(*) FROM `order` " +
            "WHERE 1=1 " +
            "AND create_time BETWEEN #{timeB} AND #{timeE} " +
            "AND `status` = #{status} " +
            "</script>")
    public Integer getCountOfOrder(@Param("timeB") String timeB,
                                   @Param("timeE") String timeE,
                                   @Param("status") Integer status);

    /**
     * 根据订单id查询商品id
     * SELECT goods_id FROM `order` o WHERE o.id = 'cb58c304-ce8a-11eb-9427-0a80ff2603de';
     * @param id
     * @return
     */
    @Select("SELECT goods_id FROM `order` o WHERE o.id = #{id}")
    public Integer getGoodsByOrderId(@Param("id") String id);
}
